<%@ page session="false"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page
	import="javax.jcr.*,java.util.*,demo.inf.*,demo.model.*,org.apache.sling.api.resource.Resource"%>
<%@ taglib prefix="sling"
	uri="http://sling.apache.org/taglibs/sling/1.0"%>

<sling:defineObjects />

<%
	BibleUploadService bibleUploadService = sling
			.getService(demo.inf.BibleUploadService.class);
	List<UploadStatus> biblesStatus = bibleUploadService
			.getBiblesStatus();
	List<UploadStatus> xrefsStatus = bibleUploadService
			.getXrefsStatus();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bible Assets Management</title>
</head>

<body>
	<a href="/bibles.html">Bibles:</a>
	<table>
		<tr>
			<th>Name</th>
			<th>Path</th>
			<th>Action</th>
		</tr>
		<%
			for (UploadStatus uploadStatus : biblesStatus) {
		%>
		<tr>
			<td><%=uploadStatus.name%></td>
			<td><%=uploadStatus.path%></td>
			<td><a href="?path=<%=uploadStatus.path%>">Process</a> | <a href="?clear=true&path=<%=uploadStatus.path%>">Process with clear</a></td>
		</tr>
		<%
			}
		%>
	</table>
	
	<hr/>
	<a href="/bibles.html">xrefs:</a>
	<table>
		<tr>
			<th>Name</th>
			<th>Path</th>
			<th>Action</th>
		</tr>
		<%
			for (UploadStatus uploadStatus : xrefsStatus) {
		%>
		<tr>
			<td><%=uploadStatus.name%></td>
			<td><%=uploadStatus.path%></td>
			<td><a href="?path=<%=uploadStatus.path%>">Process</a> | <a href="?clear=true&path=<%=uploadStatus.path%>">Process with clear</a></td>
		</tr>
		<%
			}
		%>
	</table>
	<%
		String path = request.getParameter("path");
		boolean clear = "true".equals(request.getParameter("clear"));
		
		if(path != null){
			boolean status = bibleUploadService.process(path, clear);
			%>
			<h3>Processing <%=path %>: <%=status %> (Clear=<%=clear %>) </h3>
			<%
		}
	%>
</body>
</html>